<?php 
$zone = $_POST['zone'];
$country = $_POST['countryname'];
$authorised = $_POST['authorised'];
	
if(isset($_POST['savecity']))
{
	
	if($_GET['m']!=edit)
	{
		mysql_query("insert into city (zone_id,city_name,active_status) values ('$zone','$country','$authorised')");	
		
		echo "<script>window.location='index.php?tc=addcity&_s=1'</script>";
	}
	
}
if(isset($_POST['updatecity']))

{
	

	mysql_query("update city set zone_id='$zone',city_name='$country ',active_status='$authorised' where city_id='".$_POST['hid']."'") or die(mysql_error());
	
	echo "<script>window.location='index.php?tc=city&_s=1'</script>";
	
}
?>

<script type="text/javascript">
function validate()
{
	if(document.up.countryname.value=="")
	{
		alert("Please Enter City name.");	
		document.up.countryname.focus();
		return false;
	}
}
</script>
<?php if($_REQUEST['_s'] == 1){ ?>
    <div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Successfully saved.</div>
<?php } ?>
<?php if($_REQUEST['_e'] == 1){ ?>
    <div class="sucmsg"><img src="images/error.png" align="absmiddle" />&nbsp;Category name already exists.</div>
<?php } ?>
<?php 
$ssql="select * from city where city_id='".$_GET['_d']. "'";
$ssql=mysql_query($ssql);
$row =mysql_fetch_array($ssql);
/*echo "<pre>";
	print_r($row);
	echo "</pre>";
*/if($row['active_status']=='1')
{
	
$chkact = 'checked="checked"';
}
if($row['active_status']=='0')
{
	
$chkdec = 'checked="checked"';
}
?>
<form name="up" action="#" method="post" onSubmit="return validate()">
<table width="99%" align="center" border="0"  class="list" cellpadding="5">
<input type="hidden" name="hid" value="<?php echo  $row['city_id'];?>" />
<thead>
<tr>
	<td colspan="2" align="left">
        <div style="float:left" class="righthead">City</div>
        <div style="float:right"><a href="index.php?tc=city" class="back">View City</a></div>
    </td>
</tr>
</thead>
<tr>
	<td align="right" width="150">Zone Name</td>
    <td align="left">
<select name="zone" id="zone" class="txtborder" style="width:220px;">
    <?php 
	
	
$ads=mysql_query("select * from zone where active_status='1' order by id ASC");
while($tech=mysql_fetch_array($ads)){
	
	?>
    <option <?php if($row['zone_id']==$tech['id']){echo "selected";}?> value="<?php echo $tech['id']?>">
	<?php echo $tech['zone_name']?></option>
    <?php }?>
    </select></td></tr>
<tr>
	<td align="right" width="150">City Name</td>
    <td align="left"><input type="text" name="countryname" id="countryname" style="width:200px;" value="<?php echo $row['city_name']; ?>"  /></td>
</tr>
<tr>
  <td align="right" width="150">Status :</td>
  <td align="left">
  <input name="authorised" type="radio"  value="1" checked="checked" <?php echo $chkact;?> />&nbsp;Active&nbsp;&nbsp;
  <input  name="authorised" type="radio" value="0" <?php echo $chkdec;?> />&nbsp;Deactive</td>
</tr>

<tr>
	<td colspan="2" style="padding-left:155px;">
    	<?php if($_GET['m']!=edit){?>
        <input type="submit" value="Save" name="savecity" >&nbsp;&nbsp;
        <?php }
        else
		{
         ?>
          <input type="submit" value="Update" name="updatecity" >
         <?php 
		
		}
         ?>
    </td>
</tr>        
</table>   
</form> 
